package private

import (
	"dc-go/global"
	"dc-go/model"
	"dc-go/utils"

	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type ApiUserOnline struct{}

func (a *ApiUserOnline) GetUserOnlineList(c *gin.Context) {
	var requestUserOnlineList model.RequestGetUserOnlineList
	if err := model.RequestShouldBindJSON(c, &requestUserOnlineList); err != nil {
		return
	}
	if err, userList, total := servicePrivate.ServiceUserOnline.GetUserOnlineList(requestUserOnlineList); err != nil {
		global.DcLogger.Error("获取在线用户列表失败! ", zap.Any("err", err))
		model.ResponseErrorMessage("获取在线用户列表失败, "+err.Error(), c)
	} else {
		model.ResponseSuccessData(model.ResponsePage{
			Records:  userList,
			Page:     requestUserOnlineList.Page,
			PageSize: requestUserOnlineList.PageSize,
			Total:    total,
		}, c)
	}
}

func (a *ApiUserOnline) KickUserOnlineByEmpeeAcct(c *gin.Context) {
	var toDeleteEmpeeAcct model.RequestQueryByEmpeeAcct
	if err := model.RequestShouldBindJSON(c, &toDeleteEmpeeAcct); err != nil {
		return
	}
	currentEmpeeAcct := utils.GetEmpeeAcct(c)
	err := servicePrivate.ServiceUserOnline.KickOnlineUserByEmpeeAcct(currentEmpeeAcct)
	if err != nil {
		global.DcLogger.Error("踢出用户失败! ", zap.Any("err", err))
		model.ResponseErrorMessage("踢出用户失败, "+err.Error(), c)
		return
	} else {
		global.DcLogger.Warn(utils.GetEmpeeAcct(c) + "踢出用户成功! ")
		model.ResponseSuccessMessage("踢出用户成功! ", c)
	}
}
